package com.ruoyi.project.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.PartstInfo;
import com.ruoyi.project.service.IPartstInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 零件信息Controller
 * 
 * @author ruoyi
 * @date 2022-08-27
 */
@RestController
@RequestMapping("/project/partstInfo")
public class PartstInfoController extends BaseController
{
    @Autowired
    private IPartstInfoService partstInfoService;

    /**
     * 查询零件信息列表
     */
    @PreAuthorize("@ss.hasPermi('project:partstInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(PartstInfo partstInfo)
    {
        startPage();
        List<PartstInfo> list = partstInfoService.selectPartstInfoList(partstInfo);
        return getDataTable(list);
    }

    /**
     * 导出零件信息列表
     */
    @PreAuthorize("@ss.hasPermi('project:partstInfo:export')")
    @Log(title = "零件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PartstInfo partstInfo)
    {
        List<PartstInfo> list = partstInfoService.selectPartstInfoList(partstInfo);
        ExcelUtil<PartstInfo> util = new ExcelUtil<PartstInfo>(PartstInfo.class);
        util.exportExcel(response, list, "零件信息数据");
    }

    /**
     * 获取零件信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:partstInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(partstInfoService.selectPartstInfoById(id));
    }

    /**
     * 新增零件信息
     */
    @PreAuthorize("@ss.hasPermi('project:partstInfo:add')")
    @Log(title = "零件信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PartstInfo partstInfo)
    {
        return toAjax(partstInfoService.insertPartstInfo(partstInfo));
    }

    /**
     * 修改零件信息
     */
    @PreAuthorize("@ss.hasPermi('project:partstInfo:edit')")
    @Log(title = "零件信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PartstInfo partstInfo)
    {
        return toAjax(partstInfoService.updatePartstInfo(partstInfo));
    }

    /**
     * 删除零件信息
     */
    @PreAuthorize("@ss.hasPermi('project:partstInfo:remove')")
    @Log(title = "零件信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(partstInfoService.deletePartstInfoByIds(ids));
    }

    /**
     * 导入bom
     */
    @PreAuthorize("@ss.hasPermi('project:partstInfo:uploadBom')")
    @Log(title = "零件信息", businessType = BusinessType.DELETE)
    @PostMapping("/uploadBom")
    public AjaxResult uploadBom(MultipartFile multipartFile,String projectNo, String buildNo) throws Exception {
        return partstInfoService.uploadBom(multipartFile,projectNo,buildNo);
    }

    /**
     * 导入零件
     */
    @PreAuthorize("@ss.hasPermi('project:partstInfo:uploadpartst')")
    @Log(title = "零件信息", businessType = BusinessType.DELETE)
    @PostMapping("/uploadpartst")
    public AjaxResult uploadpartst(MultipartFile multipartFile,String projectNo) throws Exception {
        return partstInfoService.uploadpartst(multipartFile,projectNo);
    }
}
